package com.springboot.codeminestarter.codemine.base.jwt;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.springboot.codeminestarter.codemine.business.user.domain.LoginUser;
import com.springboot.codeminestarter.codemine.constant.Constant;
import com.springboot.codeminestarter.codemine.utils.DateUtil;
import com.springboot.codeminestarter.codemine.wrapper.RedisWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;

//  2024/7/26 17:33  --focus
public class JWToken {
    private static final Logger LOGGER = LoggerFactory.getLogger(JWToken.class);

    @Resource
    private RedisWrapper redisWrapper;
    /**
     * 生成token
     */
    public static String generateJwtToken(LoginUser user) {
        String token = JWT.create()
                .withClaim("userId", user.getUserId())
                .withClaim("username", user.getUsername())
                .withClaim("creatTime", user.getCreateTime())
//                .withExpiresAt(DateUtil.getDate(user.getExpireTime()))
                .sign(Algorithm.HMAC256(Constant.SECRET));
        LOGGER.info("token：{}", token);
        return token;
    }

    /**
     * Token续期
     */
    public static void refreshToken(LoginUser user) {
        String expireTime = user.getExpireTime();
        String token = user.getToken();
        if (DateUtil.getTime(expireTime) < DateUtil.getCurrentTime()) {

        }
    }
}
